import axios from 'axios'
import { ElMessage } from 'element-plus'
import store from '@/store'
const request = axios.create({
  timeout:60000
})
const errorHandler = (error) => {
  ElMessage.error(error.message)
  return Promise.reject(error)
}
request.interceptors.request.use(config=>{
    console.log("请求拦截器")
    let token = store.getters.getToken
    console.log(token)
    config.headers = {
      Authorization: token
    }
    return config  
  }, errorHandler)
request.interceptors.response.use(response=>{
    const {data} = response
    if(data.code !== 200){
      ElMessage.error(data.message)
    }
    return data
  }, errorHandler)

export default request